﻿String.prototype.startsWith = function(str) 
{return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}

function checkPunctuation(input){ 
	var punctuation = "";
	var lastChar = input.charAt(input.length-1);
	if(lastChar.indexOf(".") >= 0 ||
		lastChar.indexOf(",") >= 0 ||
		lastChar.indexOf("!") >= 0 ||
		lastChar.indexOf("?") >= 0 ||
		lastChar.indexOf(":") >= 0 ||
		lastChar.indexOf(";") >= 0 ||
		lastChar.indexOf("(") >= 0) 
	{
		
		console.log(input);
		punctuation = lastChar
		console.log("punctuation "+punctuation);
	}
	return punctuation;
}

function getGender(input){
	input = input.replace(/\b[.,!?:;(]+/g, "");
	input = input.replace(/[0-9]/g, '');
	var trimmedInput = input.trim();  
	
	if(trimmedInput.endsWith("heit") ||
			trimmedInput.endsWith("keit") ||
			trimmedInput.endsWith("schaft") ||
			trimmedInput.endsWith("ei") ||
			trimmedInput.endsWith("in") ||
			trimmedInput.endsWith("ung") ||
			trimmedInput.endsWith("ion") ||
			trimmedInput.endsWith("tät") ||
			trimmedInput.endsWith("enz") ||
			trimmedInput.endsWith("ie") ||
			trimmedInput.endsWith("ik") ||
			trimmedInput.endsWith("sis") ||
			trimmedInput.endsWith("ße") ||
			trimmedInput.endsWith("lee") ||
			trimmedInput.endsWith("ur")){
			
			return 1;
	}
	else if(trimmedInput.endsWith("ling") ||
			trimmedInput.endsWith("ig") ||
			trimmedInput.endsWith("ich") ||
			trimmedInput.endsWith("ismus") ||
			trimmedInput.endsWith("ant") ||
			trimmedInput.endsWith("ast") ||
			trimmedInput.endsWith("ent") ||
			trimmedInput.endsWith("ist") ||
			trimmedInput.endsWith("or") ||
			trimmedInput.endsWith("us") ||
			trimmedInput.endsWith("tz") ||
			trimmedInput.endsWith("eg") ||
			trimmedInput.endsWith("er") ||
			trimmedInput.endsWith("en") ||
			trimmedInput.endsWith("see") ||
			trimmedInput.endsWith("ing")){
			
			return 0;
	}else{
		return 2;
	}
}

function getArticle(input, kasus){
	kasus = parseInt(kasus);
	if(kasus == 1){
		var nominativ =new Array("der", "die", "das");
		return nominativ[getGender(input)];
	}
	else if(kasus == 2){
		var genitiv =new Array("des", "der", "des");
		return genitiv[getGender(input)];
	}
	else if(kasus == 3){
		var dativ =new Array("dem", "der", "dem");
		return dativ[getGender(input)];
	}
	else if(kasus == 4){
		var akkusativ =new Array("den", "die", "das");
		return akkusativ[getGender(input)];
	}
	else{
		return "";
	}
}